package com.example.demo_news.service.Admin;

import java.util.List;

import com.example.demo_news.Repository.NewsRepository;
import com.example.demo_news.entity.News;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;


@Service
public class AdminIndexService {
    @Autowired
    private NewsRepository newsRepository;

    //返回所有新闻
    public boolean findAll(Model model){
        List<News>newsList=newsRepository.findAll();
        model.addAttribute("newsList",newsList);
        return true;
    }
    //删除条新闻
    public boolean deleteNews(Integer id){
        try {
            News news=newsRepository.findNewsById(id);
            newsRepository.delete(news);
            return true;
        } catch (Exception e) {
            return false;
        }
        

    }
}
